import Vue from "vue";
import VueRouter from "vue-router";

// 路由重复报错解决
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
  return originalPush.call(this, location).catch(() => {});
};
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: "/",
    redirect: "/product",
    component: () => import("@/layout/index.vue"),
    children: [
      {
        path: "/user",
        component: () => import("@/views/user/index.vue"),
        meta: {
          title: "用户管理",
        },
      },
      {
        path: "/product",
        redirect: "/product/category",
        meta: {
          title: "商品管理",
          icon: "el-icon-s-help",
        },
      },
      {
        path: "/product/category",
        component: () => import("@/views/product/category/index.vue"),
        meta: {
          title: "分类管理",
          icon: "el-icon-s-grid",
        },
      },
      {
        path: "/product/detail",
        component: () => import("@/views/product/detail/index.vue"),
        meta: {
          title: "详情管理",
          icon: "el-icon-s-data",
        },
      },
      {
        path: "*",
        redirect: "/product"
      },
    ],
    meta: {
      title: "首页",
    },
  },
  
];

const router = new VueRouter({
  routes,
});

export default router;
